/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package unp.sisEventos.util;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ibatis.sqlmap.engine.type.BaseTypeHandler;
import com.ibatis.sqlmap.engine.type.TypeHandler;

public class CharTypeHandler extends BaseTypeHandler implements TypeHandler {

    public CharTypeHandler() {
        super();
    }

    public Object getResult(ResultSet rs, String columnName) throws SQLException {
        String s = rs.getString(columnName);
        if (rs.wasNull()) {
            return null;
        } else {
            Character c = s.charAt(0);
            return new Character(c);
        }
    }

    public Object getResult(ResultSet rs, int columnIndex) throws SQLException {
        String s = rs.getString(columnIndex);
        if (rs.wasNull()) {
            return null;
        } else {
            Character c = s.charAt(0);
            return new Character(c);
        }
    }

    public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {
        String s = cs.getString(columnIndex);
        if (cs.wasNull()) {
            return null;
        } else {
            Character c = s.charAt(0);
            return new Character(c);
        }
    }

    public void setParameter(PreparedStatement ps, int i, Object parameter, String jdbcType) throws SQLException {
        ps.setString(i, Character.toString(((Character) parameter).charValue()));
    }

    public Object valueOf(String s) {
        return Character.valueOf(s.charAt(0));
    }
}
